package vip.ola.task.code.scheduled;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vip.ola.core.common.util.MyLog;
import vip.ola.core.entity.code.CodeOrder;
import vip.ola.task.common.service.RpcCommonService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: dingzhiwei
 * @date: 17/12/3
 * @description:
 */
@Component
public class OrderScheduled {

    @Autowired
    private RpcCommonService rpcCommonService;


    private static final MyLog _log = MyLog.getLog(OrderScheduled.class);

    /**
     * 码商过期订单
     */
    @Scheduled(cron = "0 1/1 * * * ?")  // 每一分钟执行一次
    public void handleExpireOrder() {
        LocalDateTime startTime = LocalDateTime.now().minusMinutes(10);
        LocalDateTime endTime = LocalDateTime.now().minusMinutes(5);
        List<CodeOrder> codeOrders = rpcCommonService.codeOrderService.handleExpireOrder(startTime, endTime);
        _log.info("处理码商过期订单完成, count={}, {} - {}", codeOrders.size(), startTime, endTime);
    }

}
